Source Code Viewer - Example 4 - ViewUserRatingListAction

package name.matthewgreet.example4.action;

import javax.servlet.http.HttpSession;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionSupport;

import name.matthewgreet.example4.action.FindUserRatingListByRatingAction.UserRatingByRatingListFinder;
import name.matthewgreet.example4.action.FindUserRatingListByUsernameContainsAction.UserRatingByNameContainsListFinder;
import name.matthewgreet.example4.common.AbstractViewActionSupport;
import name.matthewgreet.example4.common.ListCache;
import name.matthewgreet.example4.common.NA;
import name.matthewgreet.example4.dto.GameDTO;
import name.matthewgreet.example4.dto.UserRatingDTO;
import name.matthewgreet.example4.form.UserRatingRatingForm;
import name.matthewgreet.example4.form.UserRatingUsernameContainsForm;
import name.matthewgreet.example4.model.UserRatingPK;
import name.matthewgreet.example4.util.GameCompositeCache;
import name.matthewgreet.example4.view.GameDetailDisplay;
import name.matthewgreet.example4.view.RatingSelectBoxDisplay;
import name.matthewgreet.example4.view.UserRatingListDisplay;

/**
 * Displays search results of user ratings for a game.  
 */
@InterceptorRef("ViewStack")
@Results({
	@Result(name=ActionSupport.SUCCESS, location="/pages/UserRatingList.jsp")
})
public class ViewUserRatingListAction extends AbstractViewActionSupport {
	private static final long serialVersionUID = -7979376337555804889L;
	
	public static final int PAGE_SIZE 	= 15;
	
	private Integer masterRecordNo;
	private Integer pageNo;
	private String refresh;
	
	private UserRatingRatingForm userRatingRankForm;
	private UserRatingUsernameContainsForm userRatingUsernameContainsForm;
	
	private GameDetailDisplay gameDetailDisplay;
	private UserRatingListDisplay listDisplay;
	
	private RatingSelectBoxDisplay ratingSelectBoxDisplay;
	
	
    @Action("/ViewUserRatingList")
    @Override
    public String execute() throws Exception {
    	ListCache<NA,Integer,GameDTO> masterListCache;
    	ListCache<GameDTO,UserRatingPK,UserRatingDTO> listCache;
    	UserRatingByNameContainsListFinder userRatingByNameContainsListFinder;
    	UserRatingByRatingListFinder userRatingByRatingListFinder;
    	HttpSession session;
    	
    	session = getRequest().getSession();
    	
    	masterListCache = GameCompositeCache.getInstance(session).getMasterListCache();
    	listCache = GameCompositeCache.getInstance(session).getSlaveListCache2();
	    if (masterRecordNo != null) {
	    	masterListCache.setSelectedIndex(masterRecordNo - 1);
	    }
    	if (refresh != null) {
    		listCache.forceReload();
    	}
	    if (pageNo != null) {
	    	listCache.setPageNo(pageNo);
	    }
	    
	    if (userRatingRankForm == null) {
	    	if (listCache.getBaseRecordListFinder() instanceof UserRatingByRatingListFinder) {
	    		userRatingByRatingListFinder = (UserRatingByRatingListFinder)listCache.getBaseRecordListFinder();
	    		userRatingRankForm = new UserRatingRatingForm(userRatingByRatingListFinder.getRating());
	    	} else {
	    		userRatingRankForm = new UserRatingRatingForm();
	    	}
	    }
	    if (userRatingUsernameContainsForm == null) {
	    	if (listCache.getBaseRecordListFinder() instanceof UserRatingByNameContainsListFinder) {
	    		userRatingByNameContainsListFinder = (UserRatingByNameContainsListFinder)listCache.getBaseRecordListFinder();
	    		userRatingUsernameContainsForm = new UserRatingUsernameContainsForm(userRatingByNameContainsListFinder.getUsernameContains());
	    	} else {
	    		userRatingUsernameContainsForm = new UserRatingUsernameContainsForm();
	    	}
	    }
	    
    	gameDetailDisplay = new GameDetailDisplay(masterListCache);
    	gameDetailDisplay.init();
    	listDisplay = new UserRatingListDisplay(listCache);
    	listDisplay.init();
    	
    	ratingSelectBoxDisplay = new RatingSelectBoxDisplay();
    	ratingSelectBoxDisplay.setSelectedValue(userRatingRankForm.getRating());
	    
		return SUCCESS;
    }

    
	public Integer getMasterRecordNo() {
		return masterRecordNo;
	}
	public void setMasterRecordNo(Integer masterRecordNo) {
		this.masterRecordNo = masterRecordNo;
	}

	public Integer getPageNo() {
		return pageNo;
	}
	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}

	public String getRefresh() {
		return refresh;
	}
	public void setRefresh(String refresh) {
		this.refresh = refresh;
	}

	public GameDetailDisplay getGameDetailDisplay() {
		return gameDetailDisplay;
	}
	public UserRatingListDisplay getListDisplay() {
		return listDisplay;
	}

	public UserRatingRatingForm getUserRatingRankForm() {
		return userRatingRankForm;
	}
	public UserRatingUsernameContainsForm getUserRatingUsernameContainsForm() {
		return userRatingUsernameContainsForm;
	}


	public RatingSelectBoxDisplay getRatingSelectBoxDisplay() {
		return ratingSelectBoxDisplay;
	}

	
}